﻿using Furion.DependencyInjection;
using Microsoft.Extensions.Caching.Distributed;
using System.Windows;
using System.Windows.Controls;
using UpperComputer.WPF.Entry.Common;
using UpperComputer.WPF.Entry.Common.Extensions;
using UpperComputer.WPF.Entry.ViewModels;

namespace UpperComputer.WPF.Entry.Views
{
    /// <summary>
    /// MenuSelectControl.xaml 的交互逻辑
    /// </summary>
    public partial class MenuSelectControl : UserControl, ITransient
    {
        private readonly IDistributedCache _distributedCache;

        public MenuSelectControl(MenuSelectViewModel menuSelectViewModel, IDistributedCache distributedCache)
        {
            InitializeComponent();
            DataContext = menuSelectViewModel;
            _distributedCache = distributedCache;
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (MenuTree.SelectedItem == null)
            {
                Snackbar.ShowWarningMessage("请选择菜单");
                return;
            }
            DialogTop.CloseDialog(MenuTree.SelectedItem);
        }

        private async void DialogTop_OnDialogClosing(object sender, RoutedEventArgs e)
        {
            await _distributedCache.RemoveAsync(Constant.CACHE_KEY_MENU_CODE);
        }
    }
}
